﻿#include "HistoryChangesDialog.h"
#include "ui_HistoryChangesDialog.h"
#include "stores/DataStroes.h"
#include "utils/String/version.h"


HistoryChangesDialog::HistoryChangesDialog(QWidget *parent)
    : FDialog(parent)
    , ui(new Ui::HistoryChangesDialog)
{
    ui->setupUi(this);
    setWindowTitle(tr("History Changes"));
    ui->treeChanges->clear();
    ui->treeChanges->setColumnCount(1);
    ui->treeChanges->setHeaderHidden(true);

    auto& releaseNotes = DataStroes::instance()->releaseNotes()->model();
    if (releaseNotes.isValid()) {
        for (const auto& note : releaseNotes.data().notes) {
            QTreeWidgetItem* item = new QTreeWidgetItem(ui->treeChanges, QStringList() << note.title);
            ui->treeChanges->addTopLevelItem(item);
            QFont ft = item->font(0);
            ft.setPixelSize(15);
            item->setFont(0, ft);

            QTreeWidgetItem* itemVer = new QTreeWidgetItem(item,
                                                           QStringList() << tr("Version: %1").arg(Version::ver2str(note.version))
                                                           );
            item->addChild(itemVer);

            QTreeWidgetItem* itemDate = new QTreeWidgetItem(item, QStringList() << tr("Release Date: %1").arg(note.date));
            item->addChild(itemDate);

            QTreeWidgetItem* itemChanges = new QTreeWidgetItem(item, QStringList() << tr("Changes: "));
            item->addChild(itemChanges);

            int i = 1;
            for (const QString& change : note.changes) {
                QTreeWidgetItem* itemChange = new QTreeWidgetItem(itemChanges, QStringList() << QString("%1. %2").arg(i++, 2).arg(change));
                itemChanges->addChild(itemChange);
            }
        }
    }
}

HistoryChangesDialog::~HistoryChangesDialog()
{
    delete ui;
}
